﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using System.Data.Common;

namespace Chenxin.Lib.Business.DAL
{
    /// <summary>
    /// 数据访问类t_Personal_FinancePayedSumInfo。
    /// </summary>
    public class t_Personal_FinancePayedSumInfo
    {
        public t_Personal_FinancePayedSumInfo()
        { }
        #region  成员方法

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public static void Add(Chenxin.Lib.Business.Entity.t_Personal_FinancePayedSumInfo model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into t_Personal_FinancePayedSumInfo(");
            strSql.Append("RecordId,CityId,CityName,CompanyId,CompanyName,AreaId,AreaName,DepartId,DepartName,EmployeeId,EmployeeName,EmployeeCode,ContractArchYear,ContractArchMonth,PayArchYear,PayArchMonth,TotalReceivables,CurPayMoney,ProtophasePayMoney,CalculateYear,CalculateMonth)");

            strSql.Append(" values (");
            strSql.Append("@RecordId,@CityId,@CityName,@CompanyId,@CompanyName,@AreaId,@AreaName,@DepartId,@DepartName,@EmployeeId,@EmployeeName,@EmployeeCode,@ContractArchYear,@ContractArchMonth,@PayArchYear,@PayArchMonth,@TotalReceivables,@CurPayMoney,@ProtophasePayMoney,@CalculateYear,@CalculateMonth)");
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "RecordId", DbType.Guid, model.RecordId);
            db.AddInParameter(dbCommand, "CityId", DbType.Guid, model.CityId);
            db.AddInParameter(dbCommand, "CityName", DbType.AnsiString, model.CityName);
            db.AddInParameter(dbCommand, "CompanyId", DbType.Guid, model.CompanyId);
            db.AddInParameter(dbCommand, "CompanyName", DbType.AnsiString, model.CompanyName);
            db.AddInParameter(dbCommand, "AreaId", DbType.Guid, model.AreaId);
            db.AddInParameter(dbCommand, "AreaName", DbType.AnsiString, model.AreaName);
            db.AddInParameter(dbCommand, "DepartId", DbType.Guid, model.DepartId);
            db.AddInParameter(dbCommand, "DepartName", DbType.AnsiString, model.DepartName);
            db.AddInParameter(dbCommand, "EmployeeId", DbType.Guid, model.EmployeeId);
            db.AddInParameter(dbCommand, "EmployeeName", DbType.AnsiString, model.EmployeeName);
            db.AddInParameter(dbCommand, "EmployeeCode", DbType.AnsiString, model.EmployeeCode);
            db.AddInParameter(dbCommand, "ContractArchYear", DbType.Int32, model.ContractArchYear);
            db.AddInParameter(dbCommand, "ContractArchMonth", DbType.Int32, model.ContractArchMonth);
            db.AddInParameter(dbCommand, "PayArchYear", DbType.Int32, model.PayArchYear);
            db.AddInParameter(dbCommand, "PayArchMonth", DbType.Int32, model.PayArchMonth);
            db.AddInParameter(dbCommand, "TotalReceivables", DbType.Decimal, model.TotalReceivables);
            db.AddInParameter(dbCommand, "CurPayMoney", DbType.Decimal, model.CurPayMoney);
            db.AddInParameter(dbCommand, "ProtophasePayMoney", DbType.Decimal, model.ProtophasePayMoney);
            db.AddInParameter(dbCommand, "CalculateYear", DbType.Int32, model.CalculateYear);
            db.AddInParameter(dbCommand, "CalculateMonth", DbType.Int32, model.CalculateMonth);
            db.ExecuteNonQuery(dbCommand);
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public static void Update(Chenxin.Lib.Business.Entity.t_Personal_FinancePayedSumInfo model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update t_Personal_FinancePayedSumInfo set ");
            strSql.Append("CityId=@CityId,");
            strSql.Append("CityName=@CityName,");
            strSql.Append("CompanyId=@CompanyId,");
            strSql.Append("CompanyName=@CompanyName,");
            strSql.Append("AreaId=@AreaId,");
            strSql.Append("AreaName=@AreaName,");
            strSql.Append("DepartId=@DepartId,");
            strSql.Append("DepartName=@DepartName,");
            strSql.Append("EmployeeId=@EmployeeId,");
            strSql.Append("EmployeeName=@EmployeeName,");
            strSql.Append("EmployeeCode=@EmployeeCode,");
            strSql.Append("ContractArchYear=@ContractArchYear,");
            strSql.Append("ContractArchMonth=@ContractArchMonth,");
            strSql.Append("PayArchYear=@PayArchYear,");
            strSql.Append("PayArchMonth=@PayArchMonth,");
            strSql.Append("TotalReceivables=@TotalReceivables,");
            strSql.Append("CurPayMoney=@CurPayMoney,");
            strSql.Append("ProtophasePayMoney=@ProtophasePayMoney,");
            strSql.Append("CalculateYear=@CalculateYear,");
            strSql.Append("CalculateMonth=@CalculateMonth");
            strSql.Append(" where RecordId=@RecordId ");
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "RecordId", DbType.Guid, model.RecordId);
            db.AddInParameter(dbCommand, "CityId", DbType.Guid, model.CityId);
            db.AddInParameter(dbCommand, "CityName", DbType.AnsiString, model.CityName);
            db.AddInParameter(dbCommand, "CompanyId", DbType.Guid, model.CompanyId);
            db.AddInParameter(dbCommand, "CompanyName", DbType.AnsiString, model.CompanyName);
            db.AddInParameter(dbCommand, "AreaId", DbType.Guid, model.AreaId);
            db.AddInParameter(dbCommand, "AreaName", DbType.AnsiString, model.AreaName);
            db.AddInParameter(dbCommand, "DepartId", DbType.Guid, model.DepartId);
            db.AddInParameter(dbCommand, "DepartName", DbType.AnsiString, model.DepartName);
            db.AddInParameter(dbCommand, "EmployeeId", DbType.Guid, model.EmployeeId);
            db.AddInParameter(dbCommand, "EmployeeName", DbType.AnsiString, model.EmployeeName);
            db.AddInParameter(dbCommand, "EmployeeCode", DbType.AnsiString, model.EmployeeCode);
            db.AddInParameter(dbCommand, "ContractArchYear", DbType.Int32, model.ContractArchYear);
            db.AddInParameter(dbCommand, "ContractArchMonth", DbType.Int32, model.ContractArchMonth);
            db.AddInParameter(dbCommand, "PayArchYear", DbType.Int32, model.PayArchYear);
            db.AddInParameter(dbCommand, "PayArchMonth", DbType.Int32, model.PayArchMonth);
            db.AddInParameter(dbCommand, "TotalReceivables", DbType.Decimal, model.TotalReceivables);
            db.AddInParameter(dbCommand, "CurPayMoney", DbType.Decimal, model.CurPayMoney);
            db.AddInParameter(dbCommand, "ProtophasePayMoney", DbType.Decimal, model.ProtophasePayMoney);
            db.AddInParameter(dbCommand, "CalculateYear", DbType.Int32, model.CalculateYear);
            db.AddInParameter(dbCommand, "CalculateMonth", DbType.Int32, model.CalculateMonth);
            db.ExecuteNonQuery(dbCommand);

        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public static void Delete(Guid RecordId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from t_Personal_FinancePayedSumInfo ");
            strSql.Append(" where RecordId=@RecordId ");
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "RecordId", DbType.Guid, RecordId);
            db.ExecuteNonQuery(dbCommand);

        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public static Chenxin.Lib.Business.Entity.t_Personal_FinancePayedSumInfo GetModel(Guid RecordId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select RecordId,CityId,CityName,CompanyId,CompanyName,AreaId,AreaName,DepartId,DepartName,EmployeeId,EmployeeName,EmployeeCode,ContractArchYear,ContractArchMonth,PayArchYear,PayArchMonth,TotalReceivables,CurPayMoney,ProtophasePayMoney,CalculateYear,CalculateMonth from t_Personal_FinancePayedSumInfo ");
            strSql.Append(" where RecordId=@RecordId ");
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business_Search");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "RecordId", DbType.Guid, RecordId);
            Chenxin.Lib.Business.Entity.t_Personal_FinancePayedSumInfo model = null;
            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {
                if (dataReader.Read())
                {
                    model = ReaderBind(dataReader);
                }
                dataReader.Close();
                dataReader.Dispose();
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public static DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select RecordId,CityId,CityName,CompanyId,CompanyName,AreaId,AreaName,DepartId,DepartName,EmployeeId,EmployeeName,EmployeeCode,ContractArchYear,ContractArchMonth,PayArchYear,PayArchMonth,TotalReceivables,CurPayMoney,ProtophasePayMoney,CalculateYear,CalculateMonth ");
            strSql.Append(" FROM t_Personal_FinancePayedSumInfo ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business_Search");
            return db.ExecuteDataSet(CommandType.Text, strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            Database db = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetStoredProcCommand("UP_GetRecordByPage");
            db.AddInParameter(dbCommand, "tblName", DbType.AnsiString, "t_Personal_FinancePayedSumInfo");
            db.AddInParameter(dbCommand, "fldName", DbType.AnsiString, "ID");
            db.AddInParameter(dbCommand, "PageSize", DbType.Int32, PageSize);
            db.AddInParameter(dbCommand, "PageIndex", DbType.Int32, PageIndex);
            db.AddInParameter(dbCommand, "IsReCount", DbType.Boolean, 0);
            db.AddInParameter(dbCommand, "OrderType", DbType.Boolean, 0);
            db.AddInParameter(dbCommand, "strWhere", DbType.AnsiString, strWhere);
            return db.ExecuteDataSet(dbCommand);
        }*/

        /// <summary>
        /// 获得数据列表（比DataSet效率高，推荐使用）
        /// </summary>
        public static List<Chenxin.Lib.Business.Entity.t_Personal_FinancePayedSumInfo> GetListArray(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select RecordId,CityId,CityName,CompanyId,CompanyName,AreaId,AreaName,DepartId,DepartName,EmployeeId,EmployeeName,EmployeeCode,ContractArchYear,ContractArchMonth,PayArchYear,PayArchMonth,TotalReceivables,CurPayMoney,ProtophasePayMoney,CalculateYear,CalculateMonth ");
            strSql.Append(" FROM t_Personal_FinancePayedSumInfo ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            List<Chenxin.Lib.Business.Entity.t_Personal_FinancePayedSumInfo> list = new List<Chenxin.Lib.Business.Entity.t_Personal_FinancePayedSumInfo>();
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business_Search");
            using (IDataReader dataReader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
            {
                while (dataReader.Read())
                {
                    list.Add(ReaderBind(dataReader));
                }
                dataReader.Close();
                dataReader.Dispose();
            }
            return list;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public static DataSet ExecSql(string strSql)
        {
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business_Search");
            return db.ExecuteDataSet(CommandType.Text, strSql.ToString());
        }

        static public DataSet Proce(int Year, int Month)
        {
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business_Search");
            DbCommand dbCommand = db.GetStoredProcCommand("usp_CreatePersonalArchFinanceInfo");
            db.AddInParameter(dbCommand, "caculateYear", DbType.Int32, Year);
            db.AddInParameter(dbCommand, "caculateMonth", DbType.Int32, Month);
            return db.ExecuteDataSet(dbCommand);
        }

        static public DataSet DZProce(int Year, int Month)
        {
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business_Search");
            DbCommand dbCommand = db.GetStoredProcCommand("usp_CreateManagerArchFinanceInfo");
            db.AddInParameter(dbCommand, "caculateYear", DbType.Int32, Year);
            db.AddInParameter(dbCommand, "caculateMonth", DbType.Int32, Month);
            return db.ExecuteDataSet(dbCommand);
        }

        /// <summary>
        /// 对象实体绑定数据
        /// </summary>
        public static Chenxin.Lib.Business.Entity.t_Personal_FinancePayedSumInfo ReaderBind(IDataReader dataReader)
        {
            Chenxin.Lib.Business.Entity.t_Personal_FinancePayedSumInfo model = new Chenxin.Lib.Business.Entity.t_Personal_FinancePayedSumInfo();
            object ojb;
            ojb = dataReader["RecordId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.RecordId = new Guid(ojb.ToString());
            }
            ojb = dataReader["CityId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.CityId = new Guid(ojb.ToString());
            }
            model.CityName = dataReader["CityName"].ToString();
            ojb = dataReader["CompanyId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.CompanyId = new Guid(ojb.ToString());
            }
            model.CompanyName = dataReader["CompanyName"].ToString();
            ojb = dataReader["AreaId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.AreaId = new Guid(ojb.ToString());
            }
            model.AreaName = dataReader["AreaName"].ToString();
            ojb = dataReader["DepartId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.DepartId = new Guid(ojb.ToString());
            }
            model.DepartName = dataReader["DepartName"].ToString();
            ojb = dataReader["EmployeeId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.EmployeeId = new Guid(ojb.ToString());
            }
            model.EmployeeName = dataReader["EmployeeName"].ToString();
            model.EmployeeCode = dataReader["EmployeeCode"].ToString();
            ojb = dataReader["ContractArchYear"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ContractArchYear = (int)ojb;
            }
            ojb = dataReader["ContractArchMonth"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ContractArchMonth = (int)ojb;
            }
            ojb = dataReader["PayArchYear"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.PayArchYear = (int)ojb;
            }
            ojb = dataReader["PayArchMonth"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.PayArchMonth = (int)ojb;
            }
            ojb = dataReader["TotalReceivables"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.TotalReceivables = (decimal)ojb;
            }
            ojb = dataReader["CurPayMoney"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.CurPayMoney = (decimal)ojb;
            }
            ojb = dataReader["ProtophasePayMoney"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ProtophasePayMoney = (decimal)ojb;
            }
            ojb = dataReader["CalculateYear"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.CalculateYear = (int)ojb;
            }
            ojb = dataReader["CalculateMonth"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.CalculateMonth = (int)ojb;
            }
            return model;
        }

        #endregion  成员方法
    }
}
